package com.example.base.net

import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

/**
 * 网络请求框架
 */
object RetrofitUtils {
    fun getRetrofit():Retrofit{
        //client
        val client = OkHttpClient.Builder()
            .readTimeout(5,TimeUnit.SECONDS)
            .writeTimeout(5,TimeUnit.SECONDS)
            .connectTimeout(5,TimeUnit.SECONDS)
            .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
            .addInterceptor(TokenInterceptor())
            .build()

        val retrofit = Retrofit.Builder()
            .baseUrl(Cons.BASE_URL)
            .client(client)
            .addConverterFactory(GsonConverterFactory.create())//在这使用协程  可以自己开线程不在需要rxjava
            .build()
        return retrofit
    }
}